Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smithy/util-retry

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/util-retry

Shared retry utilities to be used in middleware packages.

  • 3.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23M
increased by5.93%
Maintainers
2
Weekly downloads
 
Created

What is @smithy/util-retry?

@smithy/util-retry is a utility package designed to provide retry functionality for operations that may fail and need to be retried. It is part of the Smithy framework, which is used by AWS SDK for JavaScript. This package helps in implementing retry strategies, handling transient errors, and ensuring that operations are retried according to specified policies.

What are @smithy/util-retry's main functionalities?

Standard Retry Strategy

This feature allows you to use a standard retry strategy for operations that might fail. The `StandardRetryStrategy` class provides a simple way to retry operations with a default policy.

const { StandardRetryStrategy } = require('@smithy/util-retry');
const retryStrategy = new StandardRetryStrategy();

async function fetchData() {
  try {
    const result = await retryStrategy.retry(() => {
      // Your operation that might fail
      return fetch('https://api.example.com/data');
    });
    console.log('Data fetched successfully:', result);
  } catch (error) {
    console.error('Failed to fetch data:', error);
  }
}

fetchData();

Custom Retry Strategy

This feature allows you to create a custom retry strategy by extending the `StandardRetryStrategy` class. You can override the `shouldRetry` method to implement custom logic for determining whether an operation should be retried.

const { StandardRetryStrategy } = require('@smithy/util-retry');

class CustomRetryStrategy extends StandardRetryStrategy {
  shouldRetry(error) {
    // Custom logic to determine if the operation should be retried
    return error.statusCode === 500;
  }
}

const customRetryStrategy = new CustomRetryStrategy();

async function fetchData() {
  try {
    const result = await customRetryStrategy.retry(() => {
      // Your operation that might fail
      return fetch('https://api.example.com/data');
    });
    console.log('Data fetched successfully:', result);
  } catch (error) {
    console.error('Failed to fetch data:', error);
  }
}

fetchData();

Exponential Backoff

This feature allows you to implement exponential backoff for retrying operations. By providing a custom `delayDecider` function, you can control the delay between retries, increasing it exponentially with each attempt.

const { StandardRetryStrategy } = require('@smithy/util-retry');
const retryStrategy = new StandardRetryStrategy({
  delayDecider: (delayBase, attempts) => Math.pow(2, attempts) * delayBase
});

async function fetchData() {
  try {
    const result = await retryStrategy.retry(() => {
      // Your operation that might fail
      return fetch('https://api.example.com/data');
    });
    console.log('Data fetched successfully:', result);
  } catch (error) {
    console.error('Failed to fetch data:', error);
  }
}

fetchData();

Other packages similar to @smithy/util-retry

Keywords

FAQs

Package last updated on 14 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc